import { Entity, PrimaryColumn, Column, UpdateDateColumn, JoinColumn, ManyToOne } from 'typeorm';
import { ClassEntity } from './class.entity';

@Entity('gateway')
export class Gateway {
  @PrimaryColumn({ type: 'char', length: 17 })
  mac: string; // MAC 地址作为主键

  @Column({ type: 'varchar', length: 255, default: '' })
  topic: string; // 订阅的主题

  @ManyToOne(() => ClassEntity, (cls) => cls.id, { onUpdate: 'NO ACTION', onDelete: 'NO ACTION' })
  @JoinColumn({ name: 'classId' })
  class: ClassEntity;

  @Column({ type: 'varchar', length: 255, default: '' })
  scene: string;

  @Column({ type: 'boolean', default: false })
  outdoor: boolean;

  @Column({ type: 'varchar', length: 255, default: '' })
  version_fs: string;

  @Column({ type: 'varchar', length: 255, default: '' })
  version_bin: string;

  @Column({ type: 'varchar', length: 255, default: '' })
  photo: string;

  @UpdateDateColumn({ type: 'timestamp', nullable: true })
  time: Date; // 在线时间（最后活动时间）

  @Column({ type: 'boolean', default: false })
  deleted: boolean;

  // 最后上报广播数据的时间
  @UpdateDateColumn({ type: 'timestamp', nullable: true })
  last_report_time: Date; // 操作时间

  // 入网时间
  @UpdateDateColumn({ type: 'timestamp', nullable: true })
  reg_time: Date; // 操作时间

  // 最后上报手环数据
  @Column({ type: 'char', nullable: true })
  last_report_wb_cnt: string;

  // 无线连接ip地址
  @Column({ type: 'varchar', length: 255, default: '' })
  sta_ip: string;

  // 以太网连接ip地址
  @Column({ type: 'varchar', length: 255, default: '' })
  eth_ip: string;

  @Column({ type: 'char', length: 17 })
  wifi_sta_mac: string;

  @Column({ type: 'char', length: 17 })
  wifi_ap_mac: string;

  @Column({ type: 'char', length: 17 })
  bt_mac: string;

  @Column({ type: 'char', length: 17 })
  eth_mac: string;

}